<template>
	<view>
		<!-- <cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="content">他的</block>
		</cu-custom> -->
		<!-- 加载动画 -->
		<!-- <view v-if="pageLoad" class="text-gray padding justify-center flex align-center">
			<u-loading mode="circle" color="#2979ff" size="40"></u-loading>
			<view class="margin-left-sm">加载中...</view>
		</view> -->
		<view>
			<view class="text-gray padding justify-center flex" v-if="Object.keys(list).length === 0"><text>暂无数据</text>
			</view>
			<view class="cu-card case isCard">
				<view class="cu-item shadow" v-for="(item,index) in list" :key="index">
					<view class="image">
						<!-- <image mode="widthFix" :src="item.imgList[0].imgurl"></image> -->
						<video v-if="item.srcVideo" :src="item.srcVideo" controls></video>
						<image class="sglist-imglist-img" v-if="item.imgList.length != 0" mode="widthFix"
							:src="item.imgList[0].imgurl"></image>
						<view class="cu-bar bg-shadeBottom"><text class="text-cut">{{item.input}}</text></view>
					</view>
					<view class="text-content padding-sm text-cut" style="width:100%;">
						{{item.value}}
					</view>
					<view class="content flex-sub">
						<view class="text-gray flex justify-around padding-bottom">
							<view @click="goDetail(item._id)" class="text-green"
								style="display: flex; align-items: center;">
								<text class="cuIcon-attention"></text>
								<view class="">
									查看
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		components: {

		},
		data() {
			return {
				list: [],
				isFirst: true,
				start: 0,
				limit: 4,
				pageLoad: true,
				ssuserid: ''
			}
		},
		onLoad: function(options) {
			this.ssuserid = options.id;
			this.getPage()
		},
		onPullDownRefresh: function() {
			this.getPage()
			uni.stopPullDownRefresh()
		},
		onReachBottom: function() {
			this.getList()
		},
		methods: {
			goDetail: function(id) {
				uni.navigateTo({
					url: "show?id=" + id
				})
			},
			goEdit: function(id) {
				uni.navigateTo({
					url: "edit?id=" + id
				})
			},
			getPage: async function() {
				var that = this;
				that.pageLoad = true
				uniCloud.callFunction({
					name: "bbs_topic",
					data: {
						cloudAction: "my",
						params: {
							ssuserid: this.ssuserid,
							start: 0,
							limit: this.limit,
						}
					}
				}).then((result) => {
					var res = result.result.data
					that.list = res.list
					that.isFirst = false
					that.start = 0 + that.limit
					that.pageLoad = false
				})
			},
			getList: function() {
				var that = this
				if (that.start == 0 && !that.isFirst) {
					return false
				}
				uniCloud.callFunction({
					name: "bbs_topic",
					data: {
						cloudAction: "my",
						params: {
							ssuserid: this.ssuserid,
							start: this.start,
							limit: this.limit,
						}
					}
				}).then((result) => {
					var res = result.result.data
					if (that.isFirst) {
						that.list = res.list
						that.isFirst = false
					} else {
						// console.log("getList")
						// console.log(that.start,res.list)
						if (res.list.length == 0) {
							that.start = 0
							return false
						}
						for (var i in res.list) {
							that.list.push(res.list[i])
						}
					}
					that.start = that.start + that.limit
				})
			},
			del: function(id) {
				var that = this
				uni.showModal({
					title: "删除提示",
					content: "删除后不可恢复",
					success: function(res) {
						if (res.confirm) {
							uniCloud.callFunction({
								name: "bbs_topic",
								data: {
									cloudAction: "delete",
									params: {
										id: id,
										ssuserid: this.ssuserid,
									}
								}
							}).then((res) => {
								for (var i in that.list) {
									if (that.list[i]._id == id) {
										that.list.splice(i, 1)
									}
								}

							})
						}
					}
				})

			}
		}
	}
</script>

<style lang="scss" scoped>

</style>
